package org.hlopik.riverGuide.controller;

import java.util.List;
import org.hlopik.riverGuide.client.model.dto.RiverGuideDTO;
import org.hlopik.riverGuide.client.services.RiverGuideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 *
 * @author f
 */
@Controller
public class AddRiverGuideController {

    @Autowired
    private RiverGuideService riverGuideService;

    public void setRiverGuideService(RiverGuideService riverGuideService) {
        this.riverGuideService = riverGuideService;
    }

    @RequestMapping("/addRiverGuide.do")
    public String handleRequest(@RequestParam("name") String name,
            @RequestParam("description") String description, Model model) throws Exception {
        RiverGuideDTO riverGuideDTO =new RiverGuideDTO();
        riverGuideDTO.setDescription(description);
        riverGuideDTO.setName(name);
        riverGuideService.addRiverGuide(riverGuideDTO);

        
        List<RiverGuideDTO> allRiverGuides = riverGuideService.getAllRiverGuides();
        model.addAttribute("allRiverGuides", allRiverGuides);
        return "showAllRiverGuides";
    }
}
